About 967 letters

About 5 minutes

#classmethod

Description: Wraps a method as a class method. See also the staticmethod function.

def classmethod(fn): ''' Wraps a method as a class method :param fn: The method to wrap :return: The wrapped method '''

The implicit first argument of a class method is the class itself, just as instance methods receive the instance as the first argument. To declare a class method, the conventional approach is:

class C: @classmethod def fn(cls, arg1, arg2): pass

Example:

class Cat: @classmethod def speak(cls): print('Meow meow meow') # Call via class Cat.speak() # Call via instance cat = Cat() cat.speak()

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

Created in 6/9/2025

Updated in 6/9/2025